//
//  GSCommonLoginVerificationCodeCountdownHandler.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/30.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginVerificationCodeCountdownHandler.h"

@interface GSCommonLoginVerificationCodeCountdownHandler ()

@property (nonatomic, strong) NSTimer *countdownTimer;

/**
 * GSCommonLoginVerificationCodeCountdownHandlerDelegate
 */
@property (nonatomic, weak) id <GSCommonLoginVerificationCodeCountdownHandlerDelegate> delegate;

@end

@implementation GSCommonLoginVerificationCodeCountdownHandler

- (instancetype)initWithCountdownDelegate:(id <GSCommonLoginVerificationCodeCountdownHandlerDelegate>)delegate;
{
    self = [super init];
    if (self) {
        self.delegate = delegate;
    }
    return self;
}


- (void)startCountdownAction {
    [self endCountdownAction];
    self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countdownTimerAction) userInfo:nil repeats:true];
}

- (void)countdownTimerAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(loginVerificationCodeCountdownHandlerCountdownAction)]) {
        [self.delegate loginVerificationCodeCountdownHandlerCountdownAction];
    }
}

- (void)endCountdownAction {
    if (_countdownTimer) {
        [_countdownTimer invalidate];
        _countdownTimer = nil;
    }
}

@end
